package com.mongo.service;

import com.mongo.func.SFunction;
import com.mongodb.client.gridfs.model.GridFSFile;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.Collection;
import java.util.List;

/**
 * 提供mongo的桶操作
 * @author xiazhun
 * @create 2022/5/27
 */
public interface LambdaGrid {

    /**
     * 获取当前查询
     * @return 当前查询
     */
    Query getQuery();
    /**
     * 查询集合{@link GridFSFile}
     * @return GridFSFile集合
     */
    List<GridFSFile> list();

    /**
     * 查询单个数据
     * @return GridFSFile
     */
    GridFSFile one();
    /**
     * 查询
     * @return GridFSFile
     */
    GridFSFile query();

    /**
     * 等于查询
     * @param function 当前引用
     * @param value 值
     * @return lambda
     */
    LambdaGrid eq(SFunction<GridFSFile,?> function, Object value);

    /**
     * 等于查询
     * @param condition 查询条件
     * @param function 当前引用
     * @param value 值
     * @return lambda
     */
    LambdaGrid eq(boolean condition, SFunction<GridFSFile, ?> function, Object value);

    /**
     * 包含查询
     * @param function 当前引用
     * @param value 值
     * @return lambda
     */
    LambdaGrid in(SFunction<GridFSFile,?> function, Object ...value);

    /**
     * 包含查询
     * @param condition 执行条件
     * @param function 字段
     * @param value 值
     * @return lambda
     */
    LambdaGrid in(boolean condition, SFunction<GridFSFile,?> function, Object ...value);

    /**
     * 包含查询
     * @param function 当前引用
     * @param value 值
     * @return lambda
     */
    LambdaGrid in(SFunction<GridFSFile,?> function, Collection<?> value);

    /**
     * 包含查询
     * @param condition 执行条件
     * @param function 字段
     * @param value 值
     * @return lambda
     */
    LambdaGrid in(boolean condition, SFunction<GridFSFile,?> function, Collection<?> value);

    /**
     * 小于查询
     * @param function 当前引用
     * @param value 值
     * @return lambda
     */
    LambdaGrid lt(SFunction<GridFSFile,?> function, Object value);

    LambdaGrid lt(boolean condition, SFunction<GridFSFile,?> function, Object value);

    /**
     * 大于查询
     * @param function 当前引用
     * @param value 值
     * @return lambda
     */
    LambdaGrid gt(SFunction<GridFSFile,?> function, Object value);

    LambdaGrid gt(boolean condition, SFunction<GridFSFile,?> function, Object value);

    /**
     * 小于等于查询
     * @param function 当前引用
     * @param value 值
     * @return lambda
     */
    LambdaGrid lte(SFunction<GridFSFile,?> function, Object value);

    LambdaGrid lte(boolean condition, SFunction<GridFSFile,?> function, Object value);

    /**
     * 大于等于查询
     * @param function 当前引用
     * @param value 值
     * @return lambda
     */
    LambdaGrid gte(SFunction<GridFSFile,?> function, Object value);

    LambdaGrid gte(boolean condition, SFunction<GridFSFile,?> function, Object value);

    /**
     * 不等于查询
     * @param function 当前引用
     * @param value 值
     * @return lambda
     */
    LambdaGrid notEq(SFunction<GridFSFile,?> function, Object value);

    LambdaGrid notEq(boolean condition, SFunction<GridFSFile,?> function, Object value);

    /**
     * 满足所有查询
     * @param function 当前引用
     * @param value 值
     * @return lambda
     */
    LambdaGrid allEq(SFunction<GridFSFile,?> function, Collection<?> value);

    LambdaGrid allEq(boolean condition, SFunction<GridFSFile,?> function, Collection<?> value);

    /**
     * 模糊查询
     * @param condition 执行条件
     * @param function 字段
     * @param value 值
     * @return lambda
     */
    LambdaGrid like(boolean condition, SFunction<GridFSFile,?> function, Object value, String regex);

    /**
     * 模糊查询
     * @param function 字段
     * @param value 值
     * @return lambda
     */
    LambdaGrid like(SFunction<GridFSFile,?> function, Object value);

    /**
     * 倒序
     * @param function 字段
     * @return lambda
     */
    LambdaGrid desc(SFunction<GridFSFile,?> function);

    /**
     * 倒序
     * @param condition 执行条件
     * @param function 字段
     * @return lambda
     */
    LambdaGrid desc(boolean condition, SFunction<GridFSFile,?> function);

    /**
     * 正序
     * @param function 字段
     * @return lambda
     */
    LambdaGrid asc(SFunction<GridFSFile,?> function);

    /**
     * 正序
     * @param condition 执行条件
     * @param function 字段
     * @return lambda
     */
    LambdaGrid asc(boolean condition, SFunction<GridFSFile,?> function);

    /**
     * 精确查询
     * @param function 当前引用
     * @param criteria 当前条件
     * @return lambda
     */
    LambdaGrid elemMatch(SFunction<GridFSFile,?> function, Criteria criteria);

    LambdaGrid between(SFunction<GridFSFile, ?> function, Object var1, Object var2);
    LambdaGrid between(boolean condition, SFunction<GridFSFile, ?> function, Object var1, Object var2);

    /**
     * 分页
     * @param pageRequest page
     * @return {@link PageImpl}
     */
    PageImpl<GridFSFile> page(PageRequest pageRequest);

}
